package com.mad.android;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;


public class MainActivity extends Activity {
	
	boolean mFlagClicked = false;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        registerForContextMenu(findViewById(R.id.MessageText));
        }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu){
    	MenuInflater i = getMenuInflater();
    	i.inflate(R.menu.my_menu, menu);
    	return true;	
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	Log.v("Menu", "Item selected: " + item.getTitle());
    	
    	if(item.getItemId() == R.id.Flag){
    		mFlagClicked = true;
    	}
    	
    	return false;
    }
    
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
    		ContextMenuInfo menuInfo) {
    	MenuInflater inflater = getMenuInflater();
    	inflater.inflate(R.menu.my_menu, menu); 
    	
    	MenuItem flag = menu.findItem(R.id.Flag);
    	flag.setEnabled(!mFlagClicked);
    	menu.setHeaderTitle("Please Select An Item");
    }
    
    @Override
    public boolean onContextItemSelected(MenuItem item) {
    	Log.v("context Menu", "Item Selected: " + item.getTitle());
    	return false;
    }
    
    public boolean onPrepareOptionsMenu(Menu menu){
    	MenuItem flag = menu.findItem(R.id.Flag);
    	flag.setEnabled(!mFlagClicked);
    	return super.onPrepareOptionsMenu(menu);
    }
   
}
       



